<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <th:block th:include="include :: header('维修申请列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
  <div class="row">
    <div class="col-sm-12 search-collapse">
      <form id="formId">
        <div class="select-list">
          <ul>
            <li>
              <label>工种：</label>
              <select name="workType" th:with="type=${@dict.getType('')}">
                <option value="">所有</option>
                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
              </select>
            </li>
            <li>
              <label>车牌号：</label>
              <input type="text" name="plateNo"/>
            </li>
            <li>
              <label>所属项目：</label>
              <select name="projectId" th:with="type=${@dict.getType('')}">
                <option value="">所有</option>
                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
              </select>
            </li>
            <li class="select-time">
              <label>维修时间：</label>
              <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginRepaireTime]"/>
              <span>-</span>
              <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endRepaireTime]"/>
            </li>
            <li>
              <label>申请人：</label>
              <input type="text" name="applyUser"/>
            </li>
            <li class="select-time">
              <label>申请时间：</label>
              <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginApplyTime]"/>
              <span>-</span>
              <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endApplyTime]"/>
            </li>
            <li>
              <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
              <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
            </li>
          </ul>
        </div>
      </form>
    </div>

    <div class="btn-group-sm" id="toolbar" role="group">
      <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="repair:repairApprove:add">
        <i class="fa fa-plus"></i> 添加
      </a>
      <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
         shiro:hasPermission="repair:repairApprove:edit">
        <i class="fa fa-edit"></i> 修改
      </a>
      <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
         shiro:hasPermission="repair:repairApprove:remove">
        <i class="fa fa-remove"></i> 删除
      </a>
      <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="repair:repairApprove:export">
        <i class="fa fa-download"></i> 导出
      </a>
    </div>
    <div class="col-sm-12 select-table table-striped">
      <table id="bootstrap-table"></table>
    </div>
  </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script th:src="@{/js/activiti.js}"></script>
<script th:inline="javascript">
  var prefix = ctx + "repair/repairApprove";
  $(function () {
    var options = {
      url: prefix + "/taskList",
      createUrl: prefix + "/add",
      updateUrl: prefix + "/edit/{id}",
      removeUrl: prefix + "/remove",
      exportUrl: prefix + "/export",
      detailUrl: prefix + "/edit/{id}",
      sortName: "applyTime",
      modalName: "维修申请",
      columns: [{
        checkbox: true
      },
        {
          field: 'id',
          title: 'null',
          visible: false
        },
        {
          field: 'username',
          title: '登录名'
        },
        {
          field: 'workType',
          title: '工种'
        },
        {
          field: 'plateNo',
          title: '车牌号'
        },
        {
          field: 'position',
          title: '地点'
        },
        {
          field: 'reason',
          title: '申请缘由'
        },
        {
          field: 'sencePics',
          title: '现场照片路径',
          visible: false
        },
        {
          field: 'scenceVideo',
          title: '现场视频录像文件路径',
          visible: false
        },
        {
          field: 'projectId',
          title: '所属项目',
        },
        {
          field: 'projectName',
          title: '所属项目',
          visible: false
        },
        {
          field: 'repaireTime',
          title: '维修时间'
        },
        {
          field: 'startTime',
          title: '开始时间',
          visible: false
        },
        {
          field: 'endTime',
          title: '结束时间',
          visible: false
        },
        {
          field: 'instanceId',
          title: '流程实例ID',
          visible: false
        },
        {
          field: 'applyUser',
          title: '申请人'
        },
        {
          field: 'applyTime',
          title: '申请时间'
        },
        {
          field: 'taskId',
          title: '当前任务ID',
          visible: false
        },
        {
          field: 'taskName',
          title: '当前任务名称',
          align: 'center',
          formatter: function (value, row, index) {
            return '<span class="badge badge-primary">' + value + '</span>';
          }
        },
        {
          field: 'realityStartTime',
          title: '实际开始时间',
          visible: false
        },
        {
          field: 'realityEndTime',
          title: '实际结束时间',
          visible: false
        },
        {
          title: '操作',
          align: 'center',
          formatter: function (value, row, index) {
            var actions = [];
            if (row.taskName.indexOf('审批') !== -1) {
              actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="showVerifyDialog(\'' + row.taskId + '\', \'' + row.taskName + '\')"><i class="fa fa-edit"></i> 审批</a> ');
            } else {
              if (row.taskName.indexOf('已挂起') === -1) {
                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="showVerifyDialog(\'' + row.taskId + '\', \'' + row.taskName + '\')"><i class="fa fa-edit"></i> ' + row.taskName + '</a> ');
              }
            }
            actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-eye"></i> 申请详情</a> ');
            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="showHistoryDialog(\'' + row.instanceId + '\')"><i class="fa fa-list"></i> 审批历史</a> ');
            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="showProcessImgDialog(\'' + row.instanceId + '\')"><i class="fa fa-image"></i> 进度查看</a> ');
            if (row.taskName.indexOf('已挂起') === -1) {
              actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="selectUser(\'' + row.taskId + '\')"><i class="fa fa-user"></i> 委托</a> ');
            }
            return actions.join('');
          }
        }]
    };
    $.table.init(options);
  });

  function showVerifyDialog(taskId, taskName) {
    var url = prefix + "/showVerifyDialog/" + taskId;
    $.modal.open(taskName, url);
  }

</script>
</body>
</html>
